Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add preStop command to destroy pod #33

Merged
merged 1 commit into from
Aug 20, 2024
Merged

add preStop command to destroy pod #33

merged 1 commit into from
Aug 20, 2024

Conversation

svor
Copy link
Collaborator

@svor svor commented Aug 9, 2024

Adds a preStop command to terminate the pod used by Molecule when the workspace is stopped

How to test:

1/ Create a workspace from https://github.com/devspaces-samples/ansible-devspaces-demo/tree/sv-preStop
2/ Run 6.Molecule: run the full molecule test command
3/ Check that test pod molecule-ubi8-python-1 is created on OS console:
screenshot-nimbusweb me-2024 08 09-16_41_33
4/ Stop the workspace
5/ Check that the test pod is terminated automatically

Related issue: https://issues.redhat.com/browse/CRW-6871

Signed-off-by: Valeriy Svydenko <[email protected]>
@svor svor self-assigned this Aug 9, 2024
@svor
Copy link
Collaborator Author

svor commented Aug 9, 2024

@dmytro-ndp could you please take a look

@dmytro-ndp
Copy link

dmytro-ndp commented Aug 19, 2024

@svor : I have tested PR using Che dogfooding instance.
Test described in the PR description has passed:
Screenshot from 2024-08-19 20-37-05

At the same time I have faced the error Failed to create temporary directory. In some cases, you may have been able to authenticate and did not have permissions on the target directory when execute the step "3.Molecule: apply the role to the pod" after the restart of workspace created from https://github.com/devspaces-samples/ansible-devspaces-demo/tree/sv-preStop and 1 and 2 commands :

 *  Executing task: devfile: 1.Molecule: start a test pod for the automation 

INFO     default scenario test matrix: dependency, create, prepare
INFO     Performing prerun with role_name_check=0...
INFO     Running default > dependency
Starting galaxy collection install process
Nothing to do. All requested collections are already installed. If you want to reinstall them, consider using `--force`.
INFO     Dependency completed successfully.
WARNING  Skipping, missing the requirements file.
INFO     Running default > create
WARNING  Skipping, instances already created.
INFO     Running default > prepare

PLAY [Create] ******************************************************************

TASK [Store user ENVs] *********************************************************
ok: [localhost]

TASK [Create local bin directory] **********************************************
changed: [localhost]

TASK [Add another bin dir to system-wide $PATH.] *******************************
ok: [localhost]

TASK [Ensure python dependencies are installed] ********************************
ok: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=4    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task: devfile: 2.Molecule: view the test instance that was created 

INFO     Running default > list
              ╷             ╷             ╷              ╷         ╷            
  Instance    │             │ Provisioner │ Scenario     │         │            
  Name        │ Driver Name │ Name        │ Name         │ Created │ Converged  
╶─────────────┼─────────────┼─────────────┼──────────────┼─────────┼───────────╴
  molecule-u… │ default     │ ansible     │ default      │ true    │ true       
              ╵             ╵             ╵              ╵         ╵            
 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task: devfile: 3.Molecule: apply the role to the pod 

INFO     default scenario test matrix: dependency, create, prepare, converge
INFO     Performing prerun with role_name_check=0...
INFO     Running default > dependency
Starting galaxy collection install process
Nothing to do. All requested collections are already installed. If you want to reinstall them, consider using `--force`.
INFO     Dependency completed successfully.
WARNING  Skipping, missing the requirements file.
INFO     Running default > create
WARNING  Skipping, instances already created.
INFO     Running default > prepare
WARNING  Skipping, instances already prepared.
INFO     Running default > converge

PLAY [Converge] ****************************************************************

TASK [Gathering Facts] *********************************************************
fatal: [molecule-ubi8-python-1]: UNREACHABLE! => {"changed": false, "msg": "Failed to create temporary directory. In some cases, you may have been able to authenticate and did not have permissions on the target directory. Consider changing the remote tmp path in ansible.cfg to a path rooted in \"/tmp\", for more error information use -vvv. Failed command was: ( umask 77 && mkdir -p \"` echo /tmp `\"&& mkdir \"` echo /tmp/ansible-tmp-1724089057.0352778-2561-23785271845334 `\" && echo ansible-tmp-1724089057.0352778-2561-23785271845334=\"` echo /tmp/ansible-tmp-1724089057.0352778-2561-23785271845334 `\" ), exited with result 1", "unreachable": true}

PLAY RECAP *********************************************************************
molecule-ubi8-python-1     : ok=0    changed=0    unreachable=1    failed=0    skipped=0    rescued=0    ignored=0

CRITICAL Ansible return code was 4, command was: ansible-playbook --inventory /home/user/.cache/molecule/extensions/default/inventory --skip-tags molecule-notest,notest /projects/ansible-devspaces-demo/collections/ansible_collections/sample_namespace/sample_collection/extensions/molecule/default/converge.yml

 *  The terminal process terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it. 

Screenshot from 2024-08-19 20-50-36

Could you take a look, please?

@svor
Copy link
Collaborator Author

svor commented Aug 20, 2024

@dmytro-ndp thank you for the review
I've tried to reproduce the error a few times on dev sandbox and on the cluster created via clusterbot but don't see the error:

TASK [Convert instance config dict to a list] **********************************
ok: [localhost]

TASK [Dump instance config] ****************************************************
changed: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=5    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

INFO     Running default > prepare

PLAY [Create] ******************************************************************

TASK [Store user ENVs] *********************************************************
ok: [localhost]

TASK [Create local bin directory] **********************************************
changed: [localhost]

TASK [Add another bin dir to system-wide $PATH.] *******************************
changed: [localhost]

TASK [Ensure python dependencies are installed] ********************************
ok: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=4    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task: devfile: 2.Molecule: view the test instance that was created 

INFO     Running default > list
                         ╷             ╷                  ╷               ╷         ╷            
  Instance Name          │ Driver Name │ Provisioner Name │ Scenario Name │ Created │ Converged  
╶────────────────────────┼─────────────┼──────────────────┼───────────────┼─────────┼───────────╴
  molecule-ubi8-python-1 │ default     │ ansible          │ default       │ true    │ false      
                         ╵             ╵                  ╵               ╵         ╵            
 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task: devfile: 3.Molecule: apply the role to the pod 

INFO     default scenario test matrix: dependency, create, prepare, converge
INFO     Performing prerun with role_name_check=0...
INFO     Running default > dependency
Starting galaxy collection install process
Nothing to do. All requested collections are already installed. If you want to reinstall them, consider using `--force`.
INFO     Dependency completed successfully.
WARNING  Skipping, missing the requirements file.
INFO     Running default > create
WARNING  Skipping, instances already created.
INFO     Running default > prepare
WARNING  Skipping, instances already prepared.
INFO     Running default > converge

PLAY [Converge] ****************************************************************

TASK [Gathering Facts] *********************************************************
ok: [molecule-ubi8-python-1]

TASK [Include backup_file] *****************************************************
included: sample_namespace.sample_collection.backup_file for molecule-ubi8-python-1

TASK [sample_namespace.sample_collection.backup_file : Ping the host] **********
ok: [molecule-ubi8-python-1]

TASK [sample_namespace.sample_collection.backup_file : Backup File | Create backup directory] ***
changed: [molecule-ubi8-python-1]

TASK [sample_namespace.sample_collection.backup_file : Backup File | Copy source file to backup destination] ***
changed: [molecule-ubi8-python-1]

PLAY RECAP *********************************************************************
molecule-ubi8-python-1     : ok=5    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

 *  Terminal will be reused by tasks, press any key to close it. 

Maybe it was some glitch when test pod was created.
Anyway I don't think it's related to the current changes. If you don't mind I'll merge current PR and when we see such error again, let's create an issue for that.

@dmytro-ndp
Copy link

dmytro-ndp commented Aug 20, 2024

@svor : thank you for the investigation.

I checked it one more time and when went through all devfile commands from 1 to 6 the command 3 executed correctly, but command 6 failed with the same error: Failed to create temporary directory. In some cases, you may have been able to authenticate and did not have permissions on the target directory

 *  Executing task: devfile: 6.Molecule: run the full molecule test 

INFO     default scenario test matrix: dependency, syntax, create, converge, idempotence, verify
INFO     Performing prerun with role_name_check=0...
INFO     Running default > dependency
Starting galaxy collection install process
Nothing to do. All requested collections are already installed. If you want to reinstall them, consider using `--force`.
INFO     Dependency completed successfully.
WARNING  Skipping, missing the requirements file.
INFO     Running default > syntax

playbook: /projects/ansible-devspaces-demo/collections/ansible_collections/sample_namespace/sample_collection/extensions/molecule/default/converge.yml
INFO     Running default > create
WARNING  Skipping, instances already created.
INFO     Running default > converge

PLAY [Converge] ****************************************************************

TASK [Gathering Facts] *********************************************************
fatal: [molecule-ubi8-python-1]: UNREACHABLE! => {"changed": false, "msg": "Failed to create temporary directory. In some cases, you may have been able to authenticate and did not have permissions on the target directory. Consider changing the remote tmp path in ansible.cfg to a path rooted in \"/tmp\", for more error information use -vvv. Failed command was: ( umask 77 && mkdir -p \"` echo /tmp `\"&& mkdir \"` echo /tmp/ansible-tmp-1724145761.9638681-5267-243090227963149 `\" && echo ansible-tmp-1724145761.9638681-5267-243090227963149=\"` echo /tmp/ansible-tmp-1724145761.9638681-5267-243090227963149 `\" ), exited with result 1", "unreachable": true}

PLAY RECAP *********************************************************************
molecule-ubi8-python-1     : ok=0    changed=0    unreachable=1    failed=0    skipped=0    rescued=0    ignored=0

CRITICAL Ansible return code was 4, command was: ansible-playbook --inventory /home/user/.cache/molecule/extensions/default/inventory --skip-tags molecule-notest,notest /projects/ansible-devspaces-demo/collections/ansible_collections/sample_namespace/sample_collection/extensions/molecule/default/converge.yml
WARNING  An error occurred during the test sequence action: 'converge'. Cleaning up.
INFO     Running default > cleanup
WARNING  Skipping, cleanup playbook not configured.
INFO     Running default > destroy

PLAY [Destroy] *****************************************************************

TASK [Destroy molecule containers] *********************************************
ok: [localhost] => (item={'image': 'registry.access.redhat.com/ubi8/python-39@sha256:301fec66443f80c3cc507ccaf72319052db5a1dc56deb55c8f169011d4bbaacb', 'name': 'molecule-ubi8-python-1', 'workingDir': '/tmp'})

TASK [Populate instance config] ************************************************
ok: [localhost]

TASK [Dump instance config] ****************************************************
skipping: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0

INFO     Pruning extra files from scenario ephemeral directory

 *  The terminal process terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it. 

I have reproduced the problem in the new workspace created from https://github.com/devspaces-samples/ansible-devspaces-demo/tree/sv-preStop - "devfile: 6.Molecule: run the full molecule test" command failed with the same error message:
Screenshot from 2024-08-20 13-09-17

@dmytro-ndp
Copy link

It seemed to be my account specific problem, because I faced the same error when triyed to execute 6.Molecule: run the full molecule test command in workspace created from Ansible sample (the issue https://issues.redhat.com/browse/CRW-7141).

@svor svor merged commit 70f34f7 into devspaces-3-rhel-8 Aug 20, 2024
1 check passed
@svor svor deleted the sv-preStop branch August 20, 2024 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants